package demo2;

import java.util.*;

//牛客网:压缩字符串(一)

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param param string字符串 
     * @return string字符串
     */
    public String compressString (String s) {
        // write code here
        int n = s.length();
        int i = 0;
        StringBuffer ret = new StringBuffer();
        while(i<n) {
            ret.append(s.charAt(i));
            int j = i+1;
            while(j<n && s.charAt(i) == s.charAt(j)) {
                j++;
            }
            int k = j-i;
            if(k>1) {
                ret.append(Integer.toString(k));
            }
            i=j;
        }

        return ret.toString();
    }
}